<template>
  <a-modal :open="open" width="1200px" title="流转记录" :footer="false" centered @cancel="onCancel">
    <div style="height: 500px">
      <div class="border p-5 relative">
        <a-button size="small" class="absolute top-0 left-0">{{ getStatus() }}</a-button>
        <div class="flex justify-around">
          <span>{{ formState.brName || '-' }}</span>
          <span>{{ formState.brXb || '-' }}</span>
          <span>{{ formState.brAge || '-' }}</span>
          <span>{{ formState.brMob || '-' }}</span>
          <span>{{ formState.admissionCode || '-' }}</span>
          <span>{{ formState.brSfz || '-' }}</span>
          <span>{{ formState.ksmc || '-' }}</span>
          <span>{{ formState.wardName || '-' }}</span>
        </div>
      </div>
      <div class="mt-10 pt-2 h-[400px] overflow-auto">
        <template v-if="circulationData.length > 0">
          <a-timeline>
            <a-timeline-item v-for="item in circulationData" :key="item">
              <div class="flex justify-between px-5 pr-10">
                <div class="flex">
                  <div class="mr-20">
                    <span class="mr-5">{{ item.addOptTime }}</span>
                    <span>{{ item.optTypeDesc }}</span>
                  </div>
                </div>
                <div class="flex-1 whitespace-pre-wrap">
                  <span class="mr-5">{{ item.circulationData }}</span>
                </div>
                <div class="pr-5">
                  <span class="mr-5">经办人 {{ item.addEmpName || '-' }}</span>
                </div>
              </div>
            </a-timeline-item>
          </a-timeline>
        </template>
        <template v-else>
          <a-empty />
        </template>
      </div>
    </div>
  </a-modal>
</template>
<script setup>
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import { post } from '@/utils/request'

const emit = defineEmits(['update:open', 'success'])
const props = defineProps({
  open: Boolean,
  rowData: {
    type: Object,
    default: () => ({})
  }
})

const formState = ref({})
const circulationData = ref([])

const getCirculationList = async () => {
  const { code, data, msg } = await post('/inp/inpComprehensive/getCirculationRecords', {
    inplsh: formState.value?.inplsh
  })
  if (code !== 0) return message.error(msg)
  circulationData.value = data
}

const onCancel = () => {
  emit('update:open', false)
}

const getStatus = () => {
  switch (formState.value.status) {
    case 0:
      return '在院'
    case 1:
      return '已出院'
    case 2:
      return '待出院'
    case 3:
      return '待入区'
    case 4:
      return '作废'
    default:
      return '-'
  }
}

watch(
  () => props.open,
  (val) => {
    if (val) {
      formState.value = props.rowData
      getCirculationList()
    }
  }
)
</script>

<style lang="less" scoped></style>
